﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace HSDc.EA.WorkflowDefinitionsTranformPlugIn
{
    public partial class Transform : Form
    {

        private DefinitionTransformer.DTO.ProcessDefinition _procDef;

        public DefinitionTransformer.DTO.ProcessDefinition ProcessDefinition
        {
            get { return _procDef; }
            set { _procDef = value; }
        }

        private bool _isConfigFinished = false;

        public bool IsConfigFinished
        {
            get { return _isConfigFinished; }
            set { _isConfigFinished = value; }
        }


        public string ProcessName
        {
            get { return this.txtName.Text; }
            set { this.txtName.Text = value; }
        }
   
        public string ProcessVersion
        {
            get { return this.txtVersion.Text; }
            set { this.txtVersion.Text = value; }
        }

        public Transform()
        {
            InitializeComponent();
        }

        public Transform(DefinitionTransformer.DTO.ProcessDefinition proc)
        {
            InitializeComponent();
            _procDef = proc;
        }

        private void Transform_Load(object sender, EventArgs e)
        {
            BindSwimlane();
            BindDecision();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            _procDef.Name = this.txtName.Text;
            _procDef.Version =Convert.ToInt32(Convert.ToDecimal( this.txtVersion.Text.Trim()));
            if (this.comboBox1.SelectedItem == "是")
                _procDef.Active = true;
            else
                _procDef.Active = false;

            this.IsConfigFinished = true;
            this.Close();
        }

        private void BindSwimlane() 
        {
            this.dataGridView1.AutoGenerateColumns = false;
            this.dataGridView1.DataSource = _procDef.Swimlanes;
            AddSLColumns();
        }

        private void AddSLColumns()
        {
            DataGridViewTextBoxColumn nameColumn =
                new DataGridViewTextBoxColumn();
            nameColumn.Name = "Name";
            nameColumn.DataPropertyName = "Name";
            nameColumn.ReadOnly = true;

            DataGridViewTextBoxColumn ruleColumn =
                   new DataGridViewTextBoxColumn();
            ruleColumn.Name = "Rule Class";
            ruleColumn.DataPropertyName = "RuleClass";
            ruleColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;

            dataGridView1.Columns.Add(nameColumn);
            dataGridView1.Columns.Add(ruleColumn);


          
        }

        private void BindDecision() 
        {
            this.dataGridView2.AutoGenerateColumns = false;
            this.dataGridView2.DataSource = _procDef.Decisions;
            AddDecColumns();

        }
        private void AddDecColumns()
        {
            DataGridViewTextBoxColumn nameColumn =
                new DataGridViewTextBoxColumn();
            nameColumn.Name = "Name";
            nameColumn.DataPropertyName = "Name";
            nameColumn.ReadOnly = true;

            DataGridViewTextBoxColumn ruleColumn =
                   new DataGridViewTextBoxColumn();
            ruleColumn.Name = "Rule Class";
            ruleColumn.DataPropertyName = "RuleClass";
            ruleColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;

            dataGridView2.Columns.Add(nameColumn);
            dataGridView2.Columns.Add(ruleColumn);

            

        }

      

     

   

   
    }
}
